//-----------------------------------------------------------------------
// <copyright file="a_UserCreditTransLogDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_UserCreditTransLogDAOBase
    {
        #region Common methods
        public virtual a_UserCreditTransLog Createa_UserCreditTransLogFromReader(IDataReader reader)
        {
            a_UserCreditTransLog item = new a_UserCreditTransLog();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("CreditTransID"))) item.CreditTransID = (int)reader["CreditTransID"];
                if (!reader.IsDBNull(reader.GetOrdinal("UserID"))) item.UserID = (int)reader["UserID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Type"))) item.Type = (int)reader["Type"];
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) item.Description = (string)reader["Description"];
                if (!reader.IsDBNull(reader.GetOrdinal("Reference"))) item.Reference = (string)reader["Reference"];
                if (!reader.IsDBNull(reader.GetOrdinal("Amount"))) item.Amount = (decimal)reader["Amount"];
                if (!reader.IsDBNull(reader.GetOrdinal("Balance"))) item.Balance = (decimal)reader["Balance"];
                if (!reader.IsDBNull(reader.GetOrdinal("TransDate"))) item.TransDate = (DateTime)reader["TransDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("PointBalance"))) item.PointBalance = (int)reader["PointBalance"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_UserCreditTransLog methods
            
        public virtual void Createa_UserCreditTransLog(a_UserCreditTransLog a_UserCreditTransLog)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserCreditTransLog_ins");
                
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_UserCreditTransLog.UserID);
                database.AddInParameter(dbCommand, "@Type", DbType.Int32, a_UserCreditTransLog.Type);
                database.AddInParameter(dbCommand, "@Description", DbType.AnsiString, a_UserCreditTransLog.Description);
                database.AddInParameter(dbCommand, "@Reference", DbType.AnsiString, a_UserCreditTransLog.Reference);
                database.AddInParameter(dbCommand, "@Amount", DbType.Currency, a_UserCreditTransLog.Amount);
                database.AddInParameter(dbCommand, "@Balance", DbType.Currency, a_UserCreditTransLog.Balance);
                database.AddInParameter(dbCommand, "@TransDate", DbType.DateTime, a_UserCreditTransLog.TransDate);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_UserCreditTransLog.DomainID);
                database.AddInParameter(dbCommand, "@PointBalance", DbType.Int32, a_UserCreditTransLog.PointBalance);
                database.AddOutParameter(dbCommand, "@CreditTransID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_UserCreditTransLog.CreditTransID = (int)database.GetParameterValue(dbCommand, "@CreditTransID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_UserCreditTransLog methods
        
        public virtual void Updatea_UserCreditTransLog(a_UserCreditTransLog a_UserCreditTransLog)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserCreditTransLog_upd");            
                
                database.AddInParameter(dbCommand, "@CreditTransID", DbType.Int32, a_UserCreditTransLog.CreditTransID);
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_UserCreditTransLog.UserID);
                database.AddInParameter(dbCommand, "@Type", DbType.Int32, a_UserCreditTransLog.Type);
                database.AddInParameter(dbCommand, "@Description", DbType.AnsiString, a_UserCreditTransLog.Description);
                database.AddInParameter(dbCommand, "@Reference", DbType.AnsiString, a_UserCreditTransLog.Reference);
                database.AddInParameter(dbCommand, "@Amount", DbType.Currency, a_UserCreditTransLog.Amount);
                database.AddInParameter(dbCommand, "@Balance", DbType.Currency, a_UserCreditTransLog.Balance);
                database.AddInParameter(dbCommand, "@TransDate", DbType.DateTime, a_UserCreditTransLog.TransDate);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_UserCreditTransLog.DomainID);
                database.AddInParameter(dbCommand, "@PointBalance", DbType.Int32, a_UserCreditTransLog.PointBalance);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_UserCreditTransLog methods
        public virtual void Deletea_UserCreditTransLog(int creditTransID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserCreditTransLog_del");
                
                database.AddInParameter(dbCommand, "@CreditTransID", DbType.Int32, creditTransID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_UserCreditTransLog methods
        
        public virtual a_UserCreditTransLog Geta_UserCreditTransLog(int creditTransID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserCreditTransLog_sel");
                
                database.AddInParameter(dbCommand, "@CreditTransID", DbType.Int32, creditTransID);
                
                a_UserCreditTransLog a_UserCreditTransLog =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_UserCreditTransLog = Createa_UserCreditTransLogFromReader(reader);
                        reader.Close();
                    }
                }
                return a_UserCreditTransLog;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_UserCreditTransLogList methods
        public virtual a_UserCreditTransLogCollection Geta_UserCreditTransLogList(a_UserCreditTransLogColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserCreditTransLog_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_UserCreditTransLogCollection a_UserCreditTransLogCollection = new a_UserCreditTransLogCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_UserCreditTransLog a_UserCreditTransLog = Createa_UserCreditTransLogFromReader(reader);
                        a_UserCreditTransLogCollection.Add(a_UserCreditTransLog);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_UserCreditTransLogCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_UserCreditTransLogCollection Geta_UserCreditTransLogList(a_UserCreditTransLogColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_UserCreditTransLogList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}